package com.chen.demo;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class SchedulerTask {
    private static SimpleDateFormat dateFormat=new SimpleDateFormat("HH:mm:ss");
    @Scheduled(cron ="0/10 * * * * ?")
    public void excTask1() throws InterruptedException {
        System.out.println("Task1开始-"+dateFormat.format(new Date()));
        Thread.sleep(8000);
        System.out.println("Task1结束-"+dateFormat.format(new Date()));
    }

    @Scheduled(cron ="0/5 * * * * ?")
    public void excTask2() throws InterruptedException {
        System.out.println("Task2开始-"+dateFormat.format(new Date()));
        Thread.sleep(2000);
        System.out.println("Task2结束-"+dateFormat.format(new Date()));
    }
}
